<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var obj = {
            name: "张三",
            info: {
                isSingle: true,
                tel: {
                    num:110,
                    type: "中国移动"
                }
            }
        }

        // var obj2 = obj
        // obj2.name = "李四"
        // console.log(obj)
    //    var obj2 = Object.assign({}, obj)
      
    //    obj2.info.isSingle = false
    //    console.log(obj)

        // var obj2 = {}
        // for(let key in obj) {
        //     obj2[key] = obj[key]
        // }
        // console.log(obj2)
        // obj2.info.isSingle = false
        // console.log(obj)
        // 除了json和递归其他的赋值语句全部是浅复制

        // var json = JSON.stringify(obj)
        // console.log(json)

        // var obj2 = JSON.parse(json) 
        
        // obj2.info.isSingle = false
        // console.log(obj)
        function deepCopy(parmas){
            let obj = {}
            if(parmas instanceof Object ) {
                for(let key in parmas) {
                    if(parmas[key] instanceof Object) {
                        obj[key] = deepCopy(parmas[key])
                    } else {
                        obj[key] = parmas[key]
                    }
                }
            }
            return obj
        }

       var obj2 =  deepCopy(obj)
       console.log(obj2)
    //    obj2.info.isSingle = false
       console.log(obj)

    //    function show() {
    //        show()
    //    }
    //    show()
    </script>
</body>
</html>